#include<algorithm>
#include<iostream>
#include<string>
#include<string_view>

using namespace std;


bool valid(string str){
    auto pos = str.find("()");
    while(string::npos != pos){
        str.replace(pos, 2, "");
        pos = str.find("()");
    }
    return str.size() == 0 ? true : false;
}

int main(){
    assert(valid("()"));

    assert(valid("()()()"));

    assert(valid("(()())"));

    assert(valid("(())()"));

    return 0;
}